package com.dongdongshop.service.impl;

import com.dongdongshop.data.PageBean;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.mapper.TbSpecificationMapper;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbSpecification;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TemplateServiceImpl implements TemplateService {



    @Autowired
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    @Autowired
    private TbBrandMapper tbBrandMapper;

    @Autowired
    private TbSpecificationMapper tbSpecificationMapper;

    @Override
    public List<TbBrand> getBrandList() {
        return tbBrandMapper.selectByExample(null);
    }

    @Override
    public List<TbSpecification> getSpecList() {
        return tbSpecificationMapper.selectByExample(null);
    }

    @Override
    public PageBean<TbTypeTemplate> getTemplateInfo(Integer pageNumber, Integer pageSize, String name) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbTypeTemplate> tbTypeTemplates = tbTypeTemplateMapper.selectByExample(null);
        PageInfo<TbTypeTemplate> info = new PageInfo<>(tbTypeTemplates);
        return new PageBean<TbTypeTemplate>(info.getPageNum(),info.getPageSize(),info.getTotal(),info.getPages(),info.getList());
    }

    @Override
    public void addTemplate(TbTypeTemplate template) {
        tbTypeTemplateMapper.insertSelective(template);
    }

    @Override
    public void deleteAll(Long[] ids) {
        tbTypeTemplateMapper.deleteAll(ids);
    }

    @Override
    public TbTypeTemplate getOneTemplate(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deleteTemplate(Long id) {
        tbTypeTemplateMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateTemplate(TbTypeTemplate template) {
        tbTypeTemplateMapper.updateByPrimaryKeySelective(template);
    }

    @Override
    public TbTypeTemplate getOneType(Long typeId) {
        return tbTypeTemplateMapper.selectByPrimaryKey(typeId);
    }
}

